result = [0] * 12


def isOk(n, pos):
    for i in range(n):
        if result[i] == pos or abs(i-n) == abs(result[i] - pos):
            return False
    return True


def Queen(n, i):
    if i == n:
        for k in range(n):
            print(result[k], end=" ")
        print("")
        return
    for k in range(n):
        if isOk(i, k):
            result[i] = k
            Queen(n, i+1)


def main():
    n = int(input())
    Queen(n, 0)


main()
